if (typeof (model) == 'undefined')
	model = {};
if (typeof (model.person) == 'undefined')
	model.person = {};

if (typeof (model.person.factory) == 'undefined')
	model.person.factory = {};

function Person(options) {
	var settings = $.extend({
		person : {}
	}, options || {});
	var self = this;
	self.id = ko.observable(settings.person.id);
	self.version = ko.observable(settings.person.version);
	self.showName = ko.observable(settings.person.showName);
	self.realName = ko.observable(settings.person.realName);
	self.location = ko.observable(settings.person.location);
	self.headPortrait = ko.observable(settings.person.headPortrait);
	self.signature = ko.observable(settings.person.signatrue || '这家伙很懒，啥签名都没写');
	self.telephone = ko.observable(settings.person.telephone);
	self.email = ko.observable(settings.person.email);
	self.qq = ko.observable(settings.person.qq);
	self.job = ko.observable(settings.person.job);
	self.workUnit = ko.observable(settings.person.workUnit);
	self.gender = ko.observable(settings.person.gender);
	self.birthday = ko.observable(settings.person.birthday);
	self.spaceView = function(){
		window.location = 'person/space.action?pid=' + self.id();
	};
	return this;
}

model.person.factory.createByPersonId = function(pid) {
	
	var url = 'person/json/get-person-of.action?pid=' + pid;
	var result = null;
	
	$.getJSON(url, function(json) {
		if (!json.error) {
			result = json.person;
		} else {
			alert(json.error);
		}
	});
	return new Person({person : result});
	
}

model.person.initializeViewModel = function(options) {
	return new Person(options);
}